﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;
using XRpgLibrary;
using XRpgLibrary.Controls;
namespace Anthem.GameScreens
{
    public class GameOverScreen : BaseGameState
    {
        #region Field region
        Texture2D backgroundImage;
        LinkLabel startLabel;
        public static bool won = false;
        #endregion
        #region Constructor region
        public GameOverScreen(Game game, GameStateManager manager)
            : base(game, manager)
        {
        }
        #endregion
        #region XNA Method region
        protected override void StateChange(object sender, EventArgs e)
        {
            if ((sender as GameStateManager).CurrentState is GameOverScreen)
            {
                Song _song = GameRef.Content.Load<Song>(@"Music\Bent and Broken");
                MediaPlayer.Play(_song);
            }
            base.StateChange(sender, e);
        }
        
        protected override void LoadContent()
        {
            ContentManager Content = GameRef.Content;
            if (won)
                backgroundImage = Content.Load<Texture2D>(@"Backgrounds\Screen_you_win");
            else
                backgroundImage = Content.Load<Texture2D>(@"Backgrounds\gameOver");
            
            base.LoadContent();
            startLabel = new LinkLabel();
            startLabel.Position = new Vector2(350, 600);
            if (!won)
                startLabel.Text = "Press ENTER to Try Again";
            else
                startLabel.Text = "Press ENTER to play another round";
            if (!won)
                startLabel.Color = Color.Red;
            else
                startLabel.Color = Color.Pink;
            won = false;
            startLabel.TabStop = true;
            startLabel.HasFocus = true;
            startLabel.Selected += new EventHandler(startLabel_Selected);
            ControlManager.Add(startLabel);
           
        }
        public override void Update(GameTime gameTime)
        {
            ControlManager.Update(gameTime, PlayerIndex.One);
            base.Update(gameTime);
        }
        public override void Draw(GameTime gameTime)
        {
            GameRef.SpriteBatch.Begin();
            base.Draw(gameTime);
            GameRef.SpriteBatch.Draw(
                backgroundImage,
                GameRef.ScreenRectangle,
                Color.White);
            ControlManager.Draw(GameRef.SpriteBatch);
            GameRef.SpriteBatch.End();
        }
        #endregion
        #region GameOver Screen Methods
        private void startLabel_Selected(object sender, EventArgs e)
        {
            StateManager.PushState(GameRef.StartMenuScreen);
        }
        #endregion
    }
}